package com.bt.lms.ui.page.teaching.plan;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bt.lms.constants.TeachingPlanBizTypeConstant;
import com.bt.lms.entity.Major;
import com.bt.lms.entity.TeachingPlanBasicInfo;
import com.bt.lms.main.BotLmsApp;
import com.bt.lms.network.msg.ReqMsg;
import com.bt.lms.network.msg.RespMsg;
import com.bt.lms.ui.action.teaching.plan.LTeachingPlanEditBtnAction;
import com.bt.lms.ui.action.teaching.plan.LTeachingPlanViewDetailsAction;
import com.bt.lms.ui.page.common.action.pageteaching.TeachingPlanLabAction;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import com.bt.lms.ui.page.sys.style.LabStyle;
import com.bt.lms.ui.page.sys.utils.MyButton;
import com.bt.lms.ui.page.sys.utils.MyLabel;
import com.bt.lms.ui.page.teaching.plan.vo.Page;
import com.bt.lms.ui.vo.teachingplan.TeachingPlanVo;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 李舒淇
 */
public class PageList extends VBox {

    //界面

    /**
     * 表格
     */
    private TableView tableView;

    /**
     * 界面的高
     */
    private Integer height = 800;

    /**
     * 第一个按钮
     */
    private Button oneBtn;

    /**
     * 第二个按钮
     */
    private Button twoBtn;

    /**
     * 第三个按钮
     */
    private Button threeBtn;

    //----------------查询----------------------
    /**
     * 所属的学习中心
     */
    private ComboBox<String> learningCenterCom;

    /**
     * 适合层次
     */
    private ComboBox<String> applyLevelCom;

    /**
     * 选择专业
     */
    private ComboBox<String> majorInfoCom;

    /**
     * 状态
     */
    private ComboBox<String> statusCom;

    /**
     * 教学计划名称
     */
    private TextField nameTF;

    //---------------------事件-------------------------

    /**
     * 新增事件
     */
    private AddAction addAction;

    /**
     * 新增关联课程
     */
    private AddCourseAction addCourseAction;

    /**
     * 分页条件查询事件
     */
    private PageAction pageAction;

    /**
     * 查看详情事件
     */
    private ViewAction viewAction;

    /**
     * 删除事件
     */
    private DeleteAction deleteAction;

    /**
     * 编辑事件
     */
    private EditAction editAction;

    /**
     * 启用事件
     */
    private EnableAction enableAction;

    /**
     * 确认完成事件
     */
    private FinishAction finishAction;

    //------------分页模型------------

    /**
     * 分页模型
     */
    private Page<TeachingPlanBasicInfo> page;

    /**
     * 列表数据
     */
    private List tableData;

    /**
     * 总记录数
     */
    private Long total;

    /**
     * 当前页
     * 默认第一页
     */
    private Integer currentPageNo = 1;

    /**
     * 每一页的条数
     * 默认每页10条
     */
    private Integer pageSize = 10;

    /**
     * 查询条件
     */
    private List searchList;

    //-------------------------------------------------------

    /**
     * 构建界面
     */
    public PageList() {

        //初始化界面
        initUI();

        //数据
        loadAndRenderPage();

    }

    /**
     * 初始化界面
     */
    private void initUI() {

        //设置内间距
        Insets insets = new Insets(10);
        this.setPadding(insets);
        //设置界面的宽
        this.setPrefWidth(BotLmsApp.PER_WIGHT);
        //设计界面的高
        this.setPrefHeight(height);

        //初始化所在位置
        initLocation();

        //初始化分页条件查询
        initPagingConditionQuery();

        //初始化新增教学计划按钮
        initAddTeachingPlanButton();

        //初始化教学计划表
        initTable();

        //初始化分页
        initQuery();

    }

    /**
     * 初始化所在位置
     */
    private void initLocation() {

        HBox hBox = new HBox();
        Insets insets = new Insets(10);
        hBox.setPadding(insets);
        Label label = new Label("当前位置：🏠>教学管理>教学计划");
        Font font = Font.font("仿宋", FontWeight.THIN, FontPosture.REGULAR, 18);
        label.setFont(font);
        hBox.getChildren().add(label);
        this.getChildren().add(hBox);

    }

    /**
     * 初始化分页条件查询
     */
    private void initPagingConditionQuery() {

        //分页查询主盒子
        VBox vBox = new VBox();
        Insets insets = new Insets(20);
        vBox.setPadding(insets);
        vBox.setSpacing(20);

        //上半部分盒子
        HBox topHBox = new HBox();
        topHBox.setSpacing(20);

        //下半部分盒子
        HBox bottomHBox = new HBox();
        bottomHBox.setSpacing(20);

        //把上半部分盒子和下半部分盒子放到分页查询的主盒子里
        ObservableList<Node> children = vBox.getChildren();
        children.addAll(topHBox, bottomHBox);

        //所属的学习中心下拉框
        learningCenterCom = new ComboBox<>();
        learningCenterCom.setId("learningCenterCom");//设置id
        learningCenterCom.getSelectionModel().select("选择所属的学习中心");
        learningCenterCom.getItems().add("清华大学");
        learningCenterCom.getItems().add("北京师范大学");
        learningCenterCom.getItems().add("山西理工大学");
        learningCenterCom.getItems().add("麻省理工大学");
        //样式
        learningCenterCom.setCursor(Cursor.HAND);

        //适合层次下拉框
        applyLevelCom = new ComboBox<>();
        applyLevelCom.setId("applyLevelCom");//设置id
        applyLevelCom.getSelectionModel().select("适合层次");
        applyLevelCom.getItems().add("免费师范生");
        applyLevelCom.getItems().add("免费师范生硕士");
        applyLevelCom.getItems().add("职后教育");
        applyLevelCom.getItems().add("其他");
        //样式
        applyLevelCom.setCursor(Cursor.HAND);

        //选择专业下拉框
        majorInfoCom = new ComboBox<>();
        majorInfoCom.setId("majorInfoCom");//设置id
        majorInfoCom.getSelectionModel().select("选择专业");
        majorInfoCom.getItems().add("java");
        majorInfoCom.getItems().add("c语言");
        majorInfoCom.getItems().add("c++语言");
        //样式
        majorInfoCom.setCursor(Cursor.HAND);

        //状态下拉框
        statusCom = new ComboBox<>();
        statusCom.setId("statusCom");//设置id
        statusCom.getSelectionModel().select("状态");
        statusCom.getItems().add("编辑中");
        statusCom.getItems().add("启用中");
        statusCom.getItems().add("已完成");
        //样式
        statusCom.setCursor(Cursor.HAND);

        //教学计划名称搜索
        //标签
        Label nameLab = new Label("教学计划名称:");
        Font font = Font.font("仿宋", FontWeight.THIN, FontPosture.REGULAR, 14);
        nameLab.setFont(font);
        //文本框
        nameTF = new TextField();
        nameTF.setId("nameTF");//设置id
        nameTF.setPromptText("输入教学计划名称");
        //搜索按钮
        Button searchBtn = new Button("搜索");
        searchBtn.setCursor(Cursor.HAND);
        //事件
        this.pageAction = new PageAction();
        searchBtn.setOnMouseClicked(pageAction);
        this.pageAction.setPageList(this);

        //放盒子里
        ObservableList<Node> children1 = topHBox.getChildren();
        children1.addAll(learningCenterCom, applyLevelCom, majorInfoCom, statusCom);

        ObservableList<Node> children2 = bottomHBox.getChildren();
        children2.addAll(nameLab, nameTF, searchBtn);

        //放入主盒子
        ObservableList<Node> children3 = this.getChildren();
        children3.add(vBox);

    }

    /**
     * 初始化新增教学计划按钮
     */
    private void initAddTeachingPlanButton() {

        //盒子
        HBox hBox = new HBox();
        hBox.setSpacing(10);
        //内间距
        Insets insets = new Insets(10);
        hBox.setPadding(insets);
        //新增教学计划按钮
        Button addBtn = new Button("新增教学计划");
        //样式
        addBtn.setCursor(Cursor.HAND);
        BtnStyle.addBtn(addBtn);
        //事件
        this.addAction = new AddAction();
        addBtn.setOnAction(addAction);
        //按钮放到盒子
        ObservableList<Node> children = hBox.getChildren();
        children.add(addBtn);
        ObservableList<Node> children1 = this.getChildren();
        children1.add(hBox);

    }

    /**
     * 初始化教学计划表
     */
    private void initTable() {

        //创建表格组件
        tableView = new TableView();
        tableView.setEditable(true);

        //创建列头
        TableColumn<TeachingPlanVo, Integer> checkBoxCol = new TableColumn<>();//多选框
        TableColumn<TeachingPlanVo, Integer> codeCol = new TableColumn<>("计划编号");
        codeCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.04);
        TableColumn<TeachingPlanVo, String> nameCol = new TableColumn<>("教学计划名称");
        nameCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.12);
        TableColumn<TeachingPlanVo, String> learningCenterCol = new TableColumn<>("所属的学习中心");
        learningCenterCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.052);
        TableColumn<TeachingPlanVo, String> belongToMajorCol = new TableColumn<>("所属专业");
        belongToMajorCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.05);
        TableColumn<TeachingPlanVo, String> applyLevelCol = new TableColumn<>("适用层次");
        applyLevelCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.08);
        TableColumn<TeachingPlanVo, String> lengthOfSchoolingCol = new TableColumn<>("学制");
        lengthOfSchoolingCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.06);
        TableColumn<TeachingPlanVo, String> statusCol = new TableColumn<>("状态");
        statusCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.05);
        TableColumn<TeachingPlanVo, String> relevanceCourseQuantityCol = new TableColumn<>("关联课程数");
        relevanceCourseQuantityCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.1);
        TableColumn<TeachingPlanVo, String> currentTermCol = new TableColumn<>("当前学期");
        currentTermCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.05);
        TableColumn<TeachingPlanVo, String> operationCol = new TableColumn<>("操作");
        operationCol.setMinWidth(BotLmsApp.PER_WIGHT * 0.22);
        //把列头放入表内
        ObservableList columns = tableView.getColumns();
        columns.addAll(checkBoxCol, codeCol, nameCol, learningCenterCol, belongToMajorCol, applyLevelCol,
                lengthOfSchoolingCol, statusCol, relevanceCourseQuantityCol, currentTermCol, operationCol);


        //配置列映射，让每一列知道要展示的属性是哪一个
        checkBoxCol.setCellValueFactory(new PropertyValueFactory<>("checkBox"));
        codeCol.setCellValueFactory(new PropertyValueFactory<>("code"));
        nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
        learningCenterCol.setCellValueFactory(new PropertyValueFactory<>("learningCenter"));
        belongToMajorCol.setCellValueFactory(new PropertyValueFactory<>("belongToMajor"));
        applyLevelCol.setCellValueFactory(new PropertyValueFactory<>("applyLevel"));
        lengthOfSchoolingCol.setCellValueFactory(new PropertyValueFactory<>("lengthOfSchooling"));
        statusCol.setCellValueFactory(new PropertyValueFactory<>("status"));
        relevanceCourseQuantityCol.setCellValueFactory(new PropertyValueFactory<>("relevanceCourseQuantity"));
        currentTermCol.setCellValueFactory(new PropertyValueFactory<>("currentTerm"));
        operationCol.setCellValueFactory(new PropertyValueFactory<>("operation"));

        //把表放到盒子里
        ObservableList<Node> children = this.getChildren();
        children.add(tableView);


    }

    /**
     * 初始化初始化分页
     */
    private void initQuery() {

        //数据控制
        int width = 45;
        Integer sumStrip = 100;//总条数
        int present = 10;//当前页数
        String presentStr = "/" + present;

        //初始化分页的盒子
        HBox queryHBox = new HBox();
        Insets insets = new Insets(10);
        queryHBox.setPadding(insets);
        queryHBox.setAlignment(Pos.CENTER_RIGHT);
        queryHBox.setSpacing(10);
        this.getChildren().add(queryHBox);

        //组件
        //首页
        MyLabel firstLab = new MyLabel("« 首页");
        queryHBox.getChildren().add(firstLab);
        //样式
        LabStyle.paging(firstLab);
        //事件
        this.pageAction = new PageAction();
        firstLab.setOnMouseClicked(this.pageAction);
        //维护关系
        this.pageAction.setPageList(this);

        //上一页
        MyLabel lastLab = new MyLabel("« 上一页");
        queryHBox.getChildren().add(lastLab);
        //样式
        LabStyle.paging(lastLab);
        //事件
        lastLab.setOnMouseClicked(this.pageAction);


        //第一个按钮
        oneBtn = new MyButton("1");
        queryHBox.getChildren().add(oneBtn);
        //样式
        BtnStyle.pagingCurrent(oneBtn);
        //事件
        oneBtn.setOnMouseClicked(this.pageAction);
        //维护关系
        this.pageAction.setPageList(this);

        //第二个按钮
        twoBtn = new MyButton("2");
        queryHBox.getChildren().add(twoBtn);
        //样式
        BtnStyle.paging(twoBtn);
        //事件
        twoBtn.setOnMouseClicked(this.pageAction);


        //第三个按钮
        threeBtn = new MyButton("3");
        queryHBox.getChildren().add(threeBtn);
        //样式
        BtnStyle.paging(threeBtn);
        //事件
        threeBtn.setOnMouseClicked(this.pageAction);

        //下一页
        MyLabel nextLab = new MyLabel("下一页 »");
        queryHBox.getChildren().add(nextLab);
        //样式
        LabStyle.paging(nextLab);
        //事件
        nextLab.setOnMouseClicked(this.pageAction);

        //尾页
        MyLabel finallyLab = new MyLabel("尾页 »");
        queryHBox.getChildren().add(finallyLab);
        //样式
        LabStyle.paging(finallyLab);
        //事件


        //条数统计
        Label explainLab = new Label("总记录数");
        queryHBox.getChildren().add(explainLab);

        Label sumLab = new Label(sumStrip + "");
        queryHBox.getChildren().add(sumLab);
        //样式
        LabStyle.status(sumLab, LabStyle.STOP);

        Label unitLab = new Label("条");
        queryHBox.getChildren().add(unitLab);

        //跳转框
        TextField pageNumberTF = new TextField();
        pageNumberTF.setPrefWidth(width);
        queryHBox.getChildren().add(pageNumberTF);

        //当前页标签
        Label presentLab = new Label(presentStr);
        queryHBox.getChildren().add(presentLab);

        //跳转按钮
        MyButton notarizeBtn = new MyButton("GO");
        queryHBox.getChildren().add(notarizeBtn);


    }


    /**
     * 加载并渲染 分页
     */
    private void loadAndRenderPage() {
        //1、获取用户输入
        List searchList1 = this.searchList;//查询条件

        Integer currentPageNo = this.currentPageNo;//当前页数
        this.page = new Page<>();//分页模型
        page.setCurrentPageNo(currentPageNo);//设置页码


        //2、组包
        String pageStr = JSON.toJSONString(page);//消息体
        String searchStr = JSON.toJSONString(searchList1);//查询条件
        String data = pageStr + searchStr;
        ReqMsg reqMsg = new ReqMsg();//消息头
        reqMsg.setBizType(TeachingPlanBizTypeConstant.PLAN_QUERY);//类型
        reqMsg.setData(pageStr);//数据
        byte[] msgByte = reqMsg.toBytes();

        //3、组网
        String ip = "127.0.0.1";
        int port = 8888;
        Socket socket = null;
        try {
            socket = new Socket(ip, port);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        //4、发送消息
        OutputStream out = null;
        try {
            out = socket.getOutputStream();
            out.write(msgByte);
            out.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        //5、接收消息
        byte[] acceptBuffer = new byte[2500];
        InputStream in = null;
        try {
            in = socket.getInputStream();
            in.read(acceptBuffer);
            in.close();
            out.close();
            socket.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        //6、解包
        RespMsg respMsg = RespMsg.toRespMsg(acceptBuffer);//给响应消息赋值
        String dataResp = respMsg.getData();//获取数据
        this.page = JSONObject.parseObject(dataResp, Page.class);//处理数据
        this.currentPageNo = page.getCurrentPageNo();//获取页码
        this.tableData = page.getTableData();//列表数据集合
        List<TeachingPlanBasicInfo> teachingPlanBasicInfos = new ArrayList<>();//新的集合

        for (int i = 0; i < tableData.size(); i++) {

            Object teachingInfo = tableData.get(i);
            String teachingInfoStr = teachingInfo.toString();
            TeachingPlanBasicInfo teachingPlanBasicInfo = JSONObject.parseObject(teachingInfoStr, TeachingPlanBasicInfo.class);
            teachingPlanBasicInfos.add(teachingPlanBasicInfo);

        }

        //7、渲染
        //处理集合里的数据转到和列表对应的VO里
        List<TeachingPlanVo> teachingPlanVos = new ArrayList<>();
        for (int i = 0; i < teachingPlanBasicInfos.size(); i++) {

            TeachingPlanBasicInfo teachingPlanBasicInfo = teachingPlanBasicInfos.get(i);

            Long id = teachingPlanBasicInfo.getID();//id

            String code = teachingPlanBasicInfo.getCode();//计划编号

            String name = teachingPlanBasicInfo.getName();//教学计划名称
            LTeachingPlanViewDetailsAction lTeachingPlanViewDetailsAction = new LTeachingPlanViewDetailsAction();


            Integer learningCenterI = teachingPlanBasicInfo.getLearningCenter();//所属的学习中心
            String learningCenter = null;
            switch (learningCenterI) {

                case 2:
                    learningCenter = "北京师范大学";
                    break;
                case 1:
                    learningCenter = "北京大学";
                    break;
            }

            Major majorInfo = teachingPlanBasicInfo.getMajorInfo();//所属专业


            Integer applyLevel = teachingPlanBasicInfo.getApplyLevel();//适用层次
            String applyLevelStr = null;
            switch (applyLevel) {
                case 1:
                    applyLevelStr = "高中";
                    break;
                case 2:
                    applyLevelStr = "大专";
                    break;
                case 3:
                    applyLevelStr = "本科";
                    break;
            }

            Integer lengthOfSchoolingText = teachingPlanBasicInfo.getLengthOfSchoolingText();//学制文本
            String lengthOfSchoolingTStr = lengthOfSchoolingText.toString();

            Integer lengthOfSchooling = teachingPlanBasicInfo.getLengthOfSchooling();//学制单位
            String lengthOfSchoolingStr = null;
            switch (lengthOfSchooling) {
                case 1:
                    lengthOfSchoolingStr = "年";
                    break;
                case 2:
                    lengthOfSchoolingStr = "月";
                    break;
                case 3:
                    lengthOfSchoolingStr = "学时";
                    break;
            }
            String lengthOfSchoolingT = lengthOfSchoolingTStr + lengthOfSchoolingStr;//学制

            Integer statusI = teachingPlanBasicInfo.getStatus();//状态
            String status = null;
            switch (statusI) {
                case 1:
                    status = "草稿";
                    break;
                case 2:
                    status = "已启用";
                    break;
                case 3:
                    status = "已完成";
                    break;
            }

            Integer relCourseQuantity = teachingPlanBasicInfo.getRelCourseQuantity();//关联课程数

            String currentTerm = teachingPlanBasicInfo.getCurrentTerm();//当前学期

            HBox operationHBox = new HBox();
            operationHBox.setSpacing(10);
            if (status.equals("草稿")) {
                Button enableBtn = new Button("启用");
                enableBtn.setCursor(Cursor.HAND);

                Button editBtn = new Button("编辑");
                editBtn.setCursor(Cursor.HAND);
                LTeachingPlanEditBtnAction teachingPlanEditBtnAction = new LTeachingPlanEditBtnAction(id);
                editBtn.setOnMouseClicked(teachingPlanEditBtnAction);

                Button deleteBtn = new Button("删除");
                deleteBtn.setCursor(Cursor.HAND);
                Button addCourseBtn = new Button("新增关联课程");
                addCourseBtn.setCursor(Cursor.HAND);
                operationHBox.getChildren().addAll(enableBtn, editBtn, deleteBtn, addCourseBtn);
            } else if (status.equals("已启用")) {
                Button confirmCompletionBtn = new Button("确认完成");
                confirmCompletionBtn.setCursor(Cursor.HAND);
                operationHBox.getChildren().add(confirmCompletionBtn);
            }
            CheckBox checkBox = new CheckBox();
            TeachingPlanVo teachingPlanVo = new TeachingPlanVo(checkBox, code, name, learningCenter, "", applyLevelStr, lengthOfSchoolingT, status, relCourseQuantity, currentTerm, operationHBox);
            teachingPlanVos.add(teachingPlanVo);
        }

        //将教学计划数据集合转换成Javafx组件集合
        ObservableList<TeachingPlanVo> teachingPlanBasicInfos1 = FXCollections.observableArrayList(teachingPlanVos);
        //把数据放入表格当中
        tableView.setItems(teachingPlanBasicInfos1);

    }

    /**
     * 新增教学计划事件
     */
    class AddAction implements EventHandler {

        @Override
        public void handle(Event event) {
            //新增界面
            PageSetTeachingPlanBasicInfo pageSetTeachingPlanBasicInfo = new PageSetTeachingPlanBasicInfo();
            Pane pane = TeachingPlanLabAction.pageSkipInfo.getPane();
            Integer index = TeachingPlanLabAction.pageSkipInfo.getIndex();
            pane.getChildren().set(index, pageSetTeachingPlanBasicInfo);
        }
    }

    /**
     * 新增关联课程事件
     */
    class AddCourseAction implements EventHandler {

        @Override
        public void handle(Event event) {
            //新增关联课程界面
            PageRelevanceCourse pageRelevanceCourse = new PageRelevanceCourse();
            Pane pane = TeachingPlanLabAction.pageSkipInfo.getPane();
            Integer index = TeachingPlanLabAction.pageSkipInfo.getIndex();
            pane.getChildren().set(index, pageRelevanceCourse);
        }
    }

    /**
     * 分页查询事件
     */
    class PageAction implements EventHandler {

        private PageList pageList;

        @Override
        public void handle(Event event) {

            String btnStr = null;
            try {
                //是按钮
                Button btn = (Button) event.getSource();//获取触发事件的按钮或文本
                btnStr = btn.getText();
            } catch (ClassCastException e) {
                //是标签
                Label source = (Label) event.getSource();
                btnStr = source.getText();
            }


            if (btnStr.matches("[1-9]\\d*")) {
                int btnInt = Integer.parseInt(btnStr);
                if (btnInt > 2) {
                    Button oneBtn1 = this.pageList.oneBtn;//第一个按钮
                    oneBtn1.setText(String.valueOf(btnInt - 1));
                    Button twoBtn1 = this.pageList.twoBtn;//第二个按钮
                    twoBtn1.setText(btnStr);
                    Button threeBtn1 = this.pageList.threeBtn;//第三个按钮
                    threeBtn1.setText(String.valueOf(btnInt + 1));
                }

                this.pageList.setCurrentPageNo(btnInt);
            } else {
                //搜索按钮
                if (btnStr.equals("搜索")) {
                    //获取收索条件
                    this.pageList.searchList = new ArrayList<>();
                    //所属的学习中心
                    ComboBox learningCenterCom = (ComboBox) pageList.lookup("#learningCenterCom");
                    String learningCenterComStr = (String) learningCenterCom.getValue();
                    Integer learningCenterComValue = -1;
                    switch (learningCenterComStr) {
                        case "北京大学":
                            learningCenterComValue = 1;
                            break;
                        case "北京师范大学":
                            learningCenterComValue = 2;
                            break;
                    }
                    searchList.add(learningCenterComValue);

                    //适合层次
                    ComboBox applyLevelCom = (ComboBox) pageList.lookup("#applyLevelCom");
                    String applyLevelComStr = (String) applyLevelCom.getValue();
                    int applyLevelComValue = -1;
                    switch (applyLevelComStr) {
                        case "高中":
                            applyLevelComValue = 1;
                            break;
                        case "大专":
                            applyLevelComValue = 2;
                            break;
                        case "本科":
                            applyLevelComValue = 3;
                            break;
                    }
                    searchList.add(applyLevelComValue);

                    //专业
                    ComboBox majorInfoCom = (ComboBox) pageList.lookup("#majorInfoCom");

                    //状态
                    ComboBox statusCom = (ComboBox) pageList.lookup("#statusCom");
                    String statusComStr = (String) statusCom.getValue();
                    int statusComValue = -1;
                    switch (statusComStr) {
                        case "草稿":
                            statusComValue = 1;
                            break;
                        case "已启用":
                            statusComValue = 2;
                            break;
                        case "已完成":
                            statusComValue = 3;
                            break;
                    }
                    searchList.add(statusComValue);


                    //名称
                    TextField nameTF = (TextField) pageList.lookup("#nameTF");
                    String nameStr = nameTF.getText().trim();
                    searchList.add(nameStr);


                }

                //是label
                if (btnStr.equals("« 首页")) {
                    this.pageList.setCurrentPageNo(1);
                    Button oneBtn1 = this.pageList.oneBtn;//第一个按钮
                    oneBtn1.setText("1");
                    Button twoBtn1 = this.pageList.twoBtn;//第二个按钮
                    twoBtn1.setText("2");
                    Button threeBtn1 = this.pageList.threeBtn;//第三个按钮
                    threeBtn1.setText("3");
                }

                if (btnStr.equals("« 上一页")) {
                    Integer currentPageNo1 = this.pageList.getCurrentPageNo();
                    if (currentPageNo1 == 1) {
                        Alert alert = new Alert(Alert.AlertType.WARNING);
                        alert.setContentText("已是第一页");
                        return;
                    } else {
                        this.pageList.setCurrentPageNo(currentPageNo1 - 1);
                        if (currentPageNo1 >= 2) {
                            Button oneBtn1 = this.pageList.oneBtn;//第一个按钮
                            oneBtn1.setText(String.valueOf(currentPageNo1 - 1));
                            Button twoBtn1 = this.pageList.twoBtn;//第二个按钮
                            twoBtn1.setText(String.valueOf(currentPageNo1));
                            Button threeBtn1 = this.pageList.threeBtn;//第三个按钮
                            threeBtn1.setText(String.valueOf(currentPageNo1 + 1));
                        }
                    }
                }

                if (btnStr.equals("下一页 »")) {
                    Integer currentPageNo1 = this.pageList.getCurrentPageNo();
                    this.pageList.setCurrentPageNo(currentPageNo1 + 1);
                    if (currentPageNo1 >= 2) {
                        Button oneBtn1 = this.pageList.oneBtn;//第一个按钮
                        oneBtn1.setText(String.valueOf(currentPageNo1));
                        Button twoBtn1 = this.pageList.twoBtn;//第二个按钮
                        twoBtn1.setText(String.valueOf(currentPageNo1 + 1));
                        Button threeBtn1 = this.pageList.threeBtn;//第三个按钮
                        threeBtn1.setText(String.valueOf(currentPageNo1 + 2));
                    }


                }
            }
            //发送请求、接收响应、映射
            this.pageList.loadAndRenderPage();
        }

        public PageList getPageList() {
            return pageList;
        }

        public void setPageList(PageList pageList) {
            this.pageList = pageList;
        }
    }

    /**
     * 查看详情事件
     */
    class ViewAction implements EventHandler {

        @Override
        public void handle(Event event) {

        }
    }

    /**
     * 删除事件
     */
    class DeleteAction implements EventHandler {

        @Override
        public void handle(Event event) {

        }
    }

    /**
     * 编辑事件
     */
    class EditAction implements EventHandler {

        @Override
        public void handle(Event event) {

        }
    }

    /**
     * 启用事件
     */
    class EnableAction implements EventHandler {

        @Override
        public void handle(Event event) {

        }
    }

    /**
     * 确认完成事件
     */
    class FinishAction implements EventHandler {

        @Override
        public void handle(Event event) {

        }
    }


    public TableView getTableView() {
        return tableView;
    }

    public void setTableView(TableView tableView) {
        this.tableView = tableView;
    }


    public ComboBox<String> getLearningCenterCom() {
        return learningCenterCom;
    }

    public void setLearningCenterCom(ComboBox<String> learningCenterCom) {
        this.learningCenterCom = learningCenterCom;
    }

    public ComboBox<String> getApplyLevelCom() {
        return applyLevelCom;
    }

    public void setApplyLevelCom(ComboBox<String> applyLevelCom) {
        this.applyLevelCom = applyLevelCom;
    }

    public ComboBox<String> getMajorInfoCom() {
        return majorInfoCom;
    }

    public void setMajorInfoCom(ComboBox<String> majorInfoCom) {
        this.majorInfoCom = majorInfoCom;
    }

    public ComboBox<String> getStatusCom() {
        return statusCom;
    }

    public void setStatusCom(ComboBox<String> statusCom) {
        this.statusCom = statusCom;
    }

    public TextField getNameTF() {
        return nameTF;
    }

    public void setNameTF(TextField nameTF) {
        this.nameTF = nameTF;
    }

    public AddAction getAddAction() {
        return addAction;
    }

    public void setAddAction(AddAction addAction) {
        this.addAction = addAction;
    }

    public AddCourseAction getAddCourseAction() {
        return addCourseAction;
    }

    public void setAddCourseAction(AddCourseAction addCourseAction) {
        this.addCourseAction = addCourseAction;
    }

    public PageAction getPageAction() {
        return pageAction;
    }

    public void setPageAction(PageAction pageAction) {
        this.pageAction = pageAction;
    }

    public ViewAction getViewAction() {
        return viewAction;
    }

    public void setViewAction(ViewAction viewAction) {
        this.viewAction = viewAction;
    }

    public DeleteAction getDeleteAction() {
        return deleteAction;
    }

    public void setDeleteAction(DeleteAction deleteAction) {
        this.deleteAction = deleteAction;
    }

    public EditAction getEditAction() {
        return editAction;
    }

    public void setEditAction(EditAction editAction) {
        this.editAction = editAction;
    }

    public EnableAction getEnableAction() {
        return enableAction;
    }

    public void setEnableAction(EnableAction enableAction) {
        this.enableAction = enableAction;
    }

    public FinishAction getFinishAction() {
        return finishAction;
    }

    public void setFinishAction(FinishAction finishAction) {
        this.finishAction = finishAction;
    }

    public Page<TeachingPlanBasicInfo> getPage() {
        return page;
    }

    public void setPage(Page<TeachingPlanBasicInfo> page) {
        this.page = page;
    }

    public Button getOneBtn() {
        return oneBtn;
    }

    public void setOneBtn(Button oneBtn) {
        this.oneBtn = oneBtn;
    }

    public Button getTwoBtn() {
        return twoBtn;
    }

    public void setTwoBtn(Button twoBtn) {
        this.twoBtn = twoBtn;
    }

    public Button getThreeBtn() {
        return threeBtn;
    }

    public void setThreeBtn(Button threeBtn) {
        this.threeBtn = threeBtn;
    }

    public List getTableData() {
        return tableData;
    }

    public void setTableData(List tableData) {
        this.tableData = tableData;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Integer getCurrentPageNo() {
        return currentPageNo;
    }

    public void setCurrentPageNo(Integer currentPageNo) {
        this.currentPageNo = currentPageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public List getSearchList() {
        return searchList;
    }

    public void setSearchList(List searchList) {
        this.searchList = searchList;
    }


}
